﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Acms.Bll;

public partial class Topics_TopicGroup : BaseTopicPage
{
    public override Role.Roles[] AllowedRoles
    {
        get { return new Role.Roles[] { Role.Roles.Developer, Role.Roles.ContentEditor, Role.Roles.ContentViewer, Role.Roles.ContentPublisher }; }
    }

    public Role.Roles[] EditRoles
    {
        get { return new Role.Roles[] { Role.Roles.Developer, Role.Roles.ContentViewer, Role.Roles.ContentPublisher }; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
    }
 

    protected void  dsTopicGroup_SelectData(object sender, Acms.DataControls.SelectEventArgs<TopicGroup> e)
    {
        TopicGroup tmp = CurrentGroup;
        if (tmp != null)
        {
            e.SetData(tmp);
        }
    }
    protected void dsTopics_SelectData(object sender, Acms.DataControls.SelectEventArgs<Topic> e)
    {
        e.SetData(Topic.GetAllByTopicGroupId(TopicGroupId));
    }
    protected void dsTopics_UpdatingData(object sender, Acms.DataControls.UpdatingDataEventArgs<Topic> e)
    {
        if (e.Action == Acms.DataControls.UpdateAction.Insert)
        {
            e.Item.TopicGroupId = TopicGroupId;
        }

    }
    protected void gridTopics_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == "MoveUp" || e.CommandName == "MoveDown")
        {
            int change = 1;
            if(e.CommandName == "MoveUp")
            {
                change = -1;
            }
            List<Topic> topics = Topic.GetAllByTopicGroupId(TopicGroupId);

            Topic.Move(topics, e.Item.DataSetIndex, e.Item.DataSetIndex + change);

            gridTopics.Rebind();
            gridTopics.SelectedIndexes.Clear();
            gridTopics.SelectedIndexes.Add(e.Item.ItemIndex + change);
        }
    }
}
